/**
 * @param {number[]} nums
 * @return {number}
 */
var maximumSum = function(nums) {
  let map = new Map(), max = -1;
  function computeCount(num) {
    let result = 0;
    while(num) {
      result += num % 10;
      num = Math.floor(num / 10);
    }
    return result;
  }
  for(let i = 0; i < nums.length; i++) {
    let count = computeCount(nums[i]);
    if(map.has(count)) {
      max = Math.max(max, map.get(count) + nums[i]);
      if(nums[i] > map.get(count)) map.set(count, nums[i]);
    } else {
      map.set(count, nums[i]);
    }
  }
  return max;
};
let nums = [18,43,36,13,7];
console.log(maximumSum(nums));
nums = [10,12,19,14];
console.log(maximumSum(nums));
